#!/usr/bin/env python
# encoding: utf-8

"""
@version: ??
@author: windblue
@contact: q418584383@gmail.com
@time: 2017/11/12 13:19
"""

import codecs

class HtmlOutputer(object):

    def __init__(self):
        self.datas = []

    def collect_data(self, data):
        if data is None:
            return
        self.datas.append(data)

    def output_html(self):
        fout = codecs.open('output.html','w','utf-8')

        fout.write("<html>")
        fout.write("<body>")
        fout.write("<table>")

        for data in self.datas:
            fout.write("<tr>")
            fout.write("<td>%s</td>"% data['url'])
            fout.write("<td>%s</td>"% data['title'].encode("utf-8").decode())
            fout.write("<td>%s</td>"% data['summary'].encode("utf-8").decode())
            fout.write("<tr>")

        fout.write("</table>")
        fout.write("</body>")
        fout.write("</html>")